package vn.fsoft.gst.dao;

import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


import vn.fsoft.gst.domain.User;
/**
 * This UserDAOImpl class implement UserDAO interface
 * @author TienNM
 *
 */
@Repository
@SuppressWarnings({"unchecked"})
public class UserDAOImpl implements UserDAO{
	
	/**
	 * Get session factory from Hibernate
	 */
	@Autowired 
	private SessionFactory sessionFactory;
	
	@Transactional
	public int addUser(User user){
		Session session = sessionFactory.getCurrentSession();
		return (Integer) session.save(user);
	}
	
	@Transactional
	public List<User> getListUser(){
		Session session = sessionFactory.getCurrentSession();
		List<User> list = session.createQuery("from User").list();
		return list;
	}

	@Transactional
	public User getUserById(int Id) {
		Session session = sessionFactory.getCurrentSession();
		return (User) session.get(User.class, Id);
	}

	
}
